#ifndef _PIPEMGR_H_
#define _PIPEMGR_H_

#include <sdpipe.h>
#include <sdhlp/singleton.h>
#include <simpleobjectpool.h>

#include <hash_map>
#include "baseserver.h"

using namespace SGDP;

class CServerMgr : public ISDPipeReporter, public ISDBaseSvrMgr
{
	DECLARE_SINGLETON(CServerMgr)
public:
    
    ///Interface of ISDPipeReporter
	virtual void SDAPI OnReport(INT32 nErrCode, UINT32 dwID);

    ///Interface of ISDBaseSvrMgr
    virtual bool Send(UINT32 dwSvrID, const char * pszBuf, UINT32 dwBufLen);

	bool Init(ISDSvrHandlerMgr * poPkgHandleMgr);
	UINT32 GetLocalID(void) const;

protected:
	CServerMgr(void);
	virtual ~CServerMgr(void);

    void _OnConnected(INT32 nErrCode, UINT32 dwID);
	void _OnDisConnected(INT32 nErrCode, UINT32 dwID);

private:
    stdext::hash_map<UINT32, CBaseServer*> m_oServerMap;
    CSimpleObjPool<CBaseServer> m_oServerPool;
    ISDSvrHandlerMgr * m_poSvrHandlerMgr;
};

#endif
